"use strict";
cc._RF.push(module, 'c397bMGjMJN+rsM7DvJxo1e', 'ChangeImgUtil');
// scripts/engines/components/ChangeImgUtil.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, menu = _a.menu;
var ChangeImgUtil = /** @class */ (function (_super) {
    __extends(ChangeImgUtil, _super);
    function ChangeImgUtil() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.sfs = [];
        _this.loop = false;
        _this.spriteComponent = null;
        _this.nowIdx = 0;
        _this.tiem = 0;
        _this.tiem2 = 0;
        _this.time = 0;
        return _this;
    }
    Object.defineProperty(ChangeImgUtil.prototype, "sprite", {
        get: function () {
            if (this.spriteComponent == null)
                this.sprite = this.node.getComponent(cc.Sprite);
            return this.spriteComponent;
        },
        set: function (sp) {
            this.spriteComponent = sp;
        },
        enumerable: false,
        configurable: true
    });
    ChangeImgUtil.prototype.changeImgById = function (idx) {
        if (!this.sprite) {
            this.sprite = this.node.getComponent(cc.Sprite);
        }
        if (!this.sprite) {
            cc.warn("current node can not find cc.Sprite!");
        }
        else {
            if (this.sfs[idx] == null) {
                console.warn("没有对应的图片，图片id:", idx);
            }
            this.sprite.spriteFrame = this.sfs[idx];
            this.nowIdx = idx;
        }
    };
    ChangeImgUtil.prototype.next = function () {
        this.nowIdx++;
        if (this.nowIdx > this.sfs.length - 1) {
            if (this.loop) {
                this.nowIdx = 0;
            }
            else {
                cc.warn("it's last one");
            }
        }
        else {
        }
        this.changeImgById(this.nowIdx);
    };
    ChangeImgUtil.prototype.last = function () {
        this.nowIdx--;
        if (this.nowIdx < 0) {
            if (this.loop) {
                this.nowIdx = this.sfs.length - 1;
            }
            else {
                cc.warn("it's first one");
            }
        }
        else {
        }
        this.changeImgById(this.nowIdx);
    };
    /**
     * 播放
     * @param sum 单位帧
     * @param time 暂停时间
     * */
    ChangeImgUtil.prototype.onPlay = function (sum, time) {
        this.onStop();
        this.tiem = 0;
        this.tiem2 = sum;
        this.time = time;
        this.schedule(this.onTime, sum * 0.033);
    };
    ChangeImgUtil.prototype.onTime = function () {
        this.tiem = this.tiem + this.tiem2 * 0.033;
        if (this.nowIdx >= this.sfs.length) {
            this.nowIdx = 0;
        }
        if (this.tiem >= this.time) {
            this.tiem = 0;
            this.nowIdx = 0;
            this.next();
        }
        else {
            this.next();
        }
    };
    /**暂停播放 */
    ChangeImgUtil.prototype.onStop = function () {
        this.unschedule(this.onTime);
    };
    __decorate([
        property([cc.SpriteFrame])
    ], ChangeImgUtil.prototype, "sfs", void 0);
    __decorate([
        property({ displayName: "是否循环" })
    ], ChangeImgUtil.prototype, "loop", void 0);
    ChangeImgUtil = __decorate([
        ccclass,
        menu("自定义组件/ChangeImgUtil")
    ], ChangeImgUtil);
    return ChangeImgUtil;
}(cc.Component));
exports.default = ChangeImgUtil;

cc._RF.pop();